package com.qeegoo.b2bautozityp.moudle.good.view.category;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;

import com.qeegoo.b2bautozityp.R;
import com.qeegoo.b2bautozityp.databinding.FragGoodsCategoryBinding;
import com.qeegoo.b2bautozityp.injector.component.DaggerGoodsFragmentComponent;
import com.qeegoo.b2bautozityp.moudle.base.BaseFragment;
import com.qeegoo.b2bautozityp.moudle.good.viewmodel.category.GoodsCategoryFragViewModel;

import javax.inject.Inject;

/**
 * 王少岩 在 2017/9/20 创建了它
 */

public class GoodsCategoryFragment extends BaseFragment<FragGoodsCategoryBinding> {
    @Inject
    GoodsCategoryFragViewModel mViewModel;

    public static GoodsCategoryFragment newsInstance(String title, String id) {
        Bundle bundle = new Bundle();
        bundle.putString("title", title);
        bundle.putString("id", id);
        GoodsCategoryFragment fragment = new GoodsCategoryFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.frag_goods_category;
    }

    @Override
    protected void initInjector() {
        DaggerGoodsFragmentComponent.builder().appComponent(getAppComponent()).fragmentComponent(getFragmentComponent()).build().inject(this);
    }

    @Override
    protected void initViews() {
        mBinding.setViewModel(mViewModel);
        mViewModel.title.set(getArguments().getString("title"));
        mViewModel.getCategorys(getArguments().getString("id"));
        mBinding.rvGoodsCategory.setLayoutManager(new GridLayoutManager(getActivity(), 3));
        mBinding.rvGoodsCategory.setAdapter(mViewModel.getAdapter());
    }
}
